package com.demo.dto;

import com.demo.enums.ResultCode;
import com.demo.enums.ResultCodeEnum;

/**
 * web控制器层返回的json数据的默认格式对应的Java类
 * 
 * @author: jie.deng
 * @time: 2017年4月16日 下午4:49:11
 */
public class CommResult {
	private String code; // 响应码
	private String msg; // 响应信息
	private Object data; // 响应结果

	public static CommResult err() {
		return result(ResultCodeEnum.UNKNOWN_ERR, null);
	}
	
	public static CommResult err(ResultCode result) {
		return result(result, null);
	}

	public static CommResult suc() {
		return result(ResultCodeEnum.SUCCESS, null);
	}

	public static CommResult suc(Object data) {
		return result(ResultCodeEnum.SUCCESS, data);
	}

	private static CommResult result(ResultCode result, Object data) {
		CommResult commResult = new CommResult();
		commResult.setCode(result.getCode());
		commResult.setMsg(result.getMsg());
		commResult.setData(data);
		return commResult;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
